﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SakForNet.Security;

namespace CrazyTalk.Common
{
    public static class PasswordHelper
    {
        /// <summary>
        /// Gets the password hash.
        /// </summary>
        /// <param name="pwd">The PWD.</param>
        /// <param name="salt">The salt.</param>
        /// <param name="PswFormat">The PSW format.</param>
        /// <returns></returns>
        public static string GetPasswordHash(string pwd, string salt, int PswFormat)
        {
            return MD5.MD5Encrypt(pwd);
            /*
            try
            {
                PasswordHashAlgorithm PwdHashAlgorithm = (PasswordHashAlgorithm)PswFormat;
                PasswordHash ph = new PasswordHash(salt, PwdHashAlgorithm);
                return ph.Encrypt(pwd);
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
            */
        }

        public static string GetPasswordSha1(string pwd)
        {
            try
            {
                return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "SHA1");
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
        }

        /// <summary>
        /// 原位使用加盐加密，现改为MD5加密
        /// </summary>
        /// <param name="pwd">The PWD.</param>
        /// <param name="PswFormat">The PSW format.</param>
        /// <param name="salt">The salt.</param>
        /// <returns></returns>
        public static string GetPasswordHash(string pwd, PasswordHashAlgorithm PswFormat, ref string salt)
        {
            salt = "11";
            return MD5.MD5Encrypt(pwd);
            /*
            try
            {
                salt = string.Empty;
                PasswordHashAlgorithm PwdHashAlgorithm = PswFormat;
                PasswordHash ph = new PasswordHash(salt, PwdHashAlgorithm);
                salt = ph.Salt;
                return ph.Encrypt(pwd);
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }*/
        }
    }
}
